package com.woniuxy.hrp.unityhandler;

import com.woniuxy.hrp.exception.NatException;
import com.woniuxy.hrp.exception.ValidateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description：统一异常处理类
 * @Author：曹杰克
 * @CreateTime：2022/8/30 14:54
 */
@Slf4j
@RestControllerAdvice(basePackages ={"com.woniuxy.hrp.web"})
public class GlobalAdvisor {
    @ExceptionHandler(Exception.class)
    public ResponseEntity hanlerException(Exception e){
        System.out.println(e.getClass().getName());
        e.printStackTrace();
        return ResponseEntity.FAIL;
    }
    @ExceptionHandler(NatException.class)
    public ResponseEntity hanlerNat(Exception e){
        e.printStackTrace();
        return new ResponseEntity("200","success","未输入医院名称");
    }
    @ExceptionHandler(ValidateException.class)
    public ResponseEntity hanlerValidateException(Exception e){
        e.printStackTrace();
        log.debug("令牌失效，已返回");
        return new ResponseEntity("501","fail","令牌失效");
    }
}
